package work.lianbiao;


import work.ListNode;


public class Problem206 {

    public static ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode current = head;
        while (current != null) {
            ListNode next = current.next;
            current.next = pre;
            pre = current;
            current = next;
        }
        return pre;
    }

    public static void main(String[] args) {
        Problem206 problem206 = new Problem206();
        ListNode listNode = new ListNode();
        int[] array = {1, 2, 3, 4, 5};
        ListNode listNode1 = ListNode.listNodeFromArray(array);
        ListNode listNode2 = Problem206.reverseList(listNode1);
        ListNode.printList(listNode2);
    }


}
